package com.cosina.game.robodefence.ui.drawable;

import android.graphics.Canvas;

import com.cosina.game.robodefence.dao.TowerDao;
import com.cosina.game.robodefence.data.TowerData;
import com.cosina.game.robodefence.model.Builder;
import com.cosina.game.robodefence.model.Finger;
import com.cosina.game.robodefence.ui.ImageManager;
import com.cosina.game.robodefence.ui.PaintSuite;
import com.cosina.game.robodefence.util.CanvasUtil;

public class MenuItemDrawable extends BaseDrawable {
	int buttonYSpan = 235;
	final int buttonXspan = 155 + 240;
	
	@Override
	public void draw(Canvas canvas) {

		int[] upgradeItems =  Builder.getCurrentBuilderItem();
		
		for(int i=0; i<upgradeItems.length; i++){
			
			int kind = upgradeItems[i];
			boolean canBuilder = Builder.isCanBuilder(kind);
			
			canvas.drawRect(buttonXspan  - 80*i  , 
					buttonYSpan, 
					buttonXspan  - 80*i  + 65, 
					buttonYSpan + 75, 
					PaintSuite.p4Good);
			if(canBuilder == false){
				PaintSuite.setAlpha(PaintSuite.alphaTranparent);
			}
			canvas.drawRect(buttonXspan + 1  - 80*i, 
							buttonYSpan + 1, 
							buttonXspan - 80*i  + 64, 
							buttonYSpan + 74, 
							PaintSuite.p4Bg);
			ImageManager.drawTower(upgradeItems[i], 12, canvas, 
									buttonXspan + 1  - 80*i + 12, 
									buttonYSpan + 1 + 30);
			
			String textInButton =  getDrawTextInButtonArea(kind);
			if(null != textInButton){
				CanvasUtil.drawText(canvas, textInButton, buttonXspan + 1  - 80*i + 32, buttonYSpan + 1 + 15, PaintSuite.p4Text, 15,CanvasUtil.CENTER);
			}
			PaintSuite.setAlpha(PaintSuite.alphaDefault);
		}
	}
	private String getDrawTextInButtonArea(int kind){
		if(kind == TowerData.SELL){
			return "$" + TowerDao.getSellMoney(Finger.kind);
		}
		return "$" + TowerDao.getUpgradeCost(kind);
	}
}
